package cn.sc.summer.warm.runner;

import cn.sc.summer.constant.project.ProjectConstant;
import cn.sc.summer.redis.util.NacosInstancesService;
import cn.sc.summer.redis.util.RedisHelper;
import cn.sc.summer.warm.endpoint.WarmupEndpoint;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

/**
 * 类名：warmup销毁
 *
 * @author a-xin
 * @date 2023/8/25 14:31
 */
@Slf4j
@Component
public class WarmUpRunner implements ApplicationListener<ContextClosedEvent> {

    @Override
    public void onApplicationEvent(@NonNull ContextClosedEvent event) {
        String serverName = ProjectConstant.SERVER_NAME;
        String redisKey = WarmupEndpoint.WARM_UP + serverName + ":" + NacosInstancesService.getServerNacosAddress();
        RedisHelper.del(redisKey);
    }

}
